<?
require_once('config.php');
$array_adt = author::getListAuthor();
$count_adt = count($array_adt);
?>
<?=$css_module?>
<?=$js_module?>
<div class="row-fluid">
   <div class="head">
      <div class="isw-grid"></div>
      <h1>Danh sách category</h1>    
      <div class="reload_tab" title="Reload"></div>                              
      <div class="clear"></div>
   </div>                                
   <div class="block-fluid table-sorting">
      <div id="tSortable_wrapper" class="dataTables_wrapper" >
         <div class="dataTables_filter" id="tSortable_filter">
            <form>
               <table>
                  <tr>
                     <td><label>Tìm kiếm:</label></td>
                     <td><input type="text" /></td>
                     <td><input type="submit" class="bottom btn btn-info btn-small" value="Tìm kiếm" data-original-title="" title=""/></td>
                  </tr>
               </table>
            </form>
         </div>
         <table cellpadding="0" cellspacing="0" width="100%" class="table dataTable table-bordered" id="tSortable"  style="width: 100%;">
            <thead>
              <tr>
                  <th class="sorting_disabled"  rowspan="1" colspan="1" style="width: 23px;">
                     <div class="checker">
                        <span>
                           <input type="checkbox" name="checkall" style="opacity: 0;"/>
                        </span>
                     </div>
                  </th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Sửa</th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Xóa</th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Admin ID</th>
                  <th width="20%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Admin Name</th>
                  <th width="50%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Permission</th>
               </tr>
            </thead>
              <?
              if($count_adt > 0){
                  foreach($array_adt as $value){?>
                     <tr class="even">
                        <td class=" sorting_1">
                           <div class="checker">
                              <span>
                                 <input type="checkbox" class="checkbox-row" name="row_to_delete[]" value="<?=$value['id']?>"/>
                              </span>
                           </div>
                        </td>
                        <td class="">
                           <a href="edit.php?id=<?=$value['id']?>">
                              <span class="edit-row">Sửa</span>
                           </a>
                        </td>
                        <td class="">
                           <span class="delete-row" onclick="deleteOnlyRow(this)" data-id=<?=$value['id']?>  >Xóa</span>
                        </td>
                        <td><?=$value['id']?></td>
                        <td class=" "><?=$value['name']?></td>
                        <td class=" ">
                           <ul>
                              <?php
                                 if($value['name'] == 'admin' ) echo "FULL Permisstion";
                                 else{
                                    $author = new author($value['id']);
                                    $list_permisstion = $author->list_permisstion;                                 
                                    if(count($list_permisstion) > 0){
                                       foreach($list_permisstion as $permisstion){?>
                                          <li><?=$permisstion['mod_name']?></li>
                                       <?}
                                    }   
                                 } 
                                 
                              ?>
                           </ul>
                        </td>                       
                    </tr>
                  <?}?>
              <?}?>
          </table>
         </div>
      <div class="clear"></div>
      <div class="mult_submit">
         <span>Với những dòng đã chọn: </span>  <span class="delete-row mult-delete">Xóa</span>   
      </div>
   </div>
</div>
<script>
$(function(){
   
   $('.mult-delete').click(function(){
      var matches = [];
      $(".checkbox-row:checked").each(function() {
          matches.push(this.value);
          string_cat_id = matches.join(',');
      });
      data = {'id':string_cat_id};
      var updateHTML = function(data){
         if(data != ''){
            alert(data);
            window.location.reload();
         }
      }
      var beforeSend = function(){
         
      }
      var conf = confirm("Xóa những dòng đã chọn ?");
      if(conf)
         handleAjax('delete.php','POST',data,updateHTML,beforeSend);
   });
});
</script>